package org.springblade.modules.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.dto.PartsWarehousePageDTO;
import org.springblade.modules.admin.vo.PartsWarehousePageVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.entity.PartsWarehouse;
import org.springblade.modules.admin.vo.PartsWarehouseVO;
import org.springblade.modules.admin.wrapper.PartsWarehouseWrapper;
import org.springblade.modules.admin.service.IPartsWarehouseService;
import org.springblade.core.boot.ctrl.BladeController;

/**
 * 配件仓库表 控制器
 *
 * @author ysq
 * @since 2023-08-09
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/parts/warehouse")
@Api(value = "配件仓库表", tags = "配件仓库表接口")
public class PartsWarehouseController extends BladeController {

	private final IPartsWarehouseService partsWarehouseService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入partsWarehouse")
	public R<PartsWarehouseVO> detail(PartsWarehouse partsWarehouse) {
		PartsWarehouse detail = partsWarehouseService.getOne(Condition.getQueryWrapper(partsWarehouse));
		return R.data(PartsWarehouseWrapper.build().entityVO(detail));
	}

	/**
	 * 自定义分页 配件仓库表
	 */
	@PostMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入partsWarehouse")
	public R<IPage<PartsWarehouseVO>> page(PartsWarehouseVO partsWarehouse, Query query) {
		IPage<PartsWarehouseVO> pages
			= partsWarehouseService.selectPartsWarehousePage(Condition.getPage(query), partsWarehouse);
		return R.data(pages);
	}

	/**
	 * 分页 配件仓库表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入partsWarehouse")
	public R<IPage<PartsWarehouseVO>> list(PartsWarehouse partsWarehouse, Query query) {
		IPage<PartsWarehouse> pages = partsWarehouseService.page(Condition.getPage(query), Condition.getQueryWrapper(partsWarehouse));
		return R.data(PartsWarehouseWrapper.build().pageVO(pages));
	}

	/**
	 * 新增或修改 配件仓库表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "新增或修改", notes = "传入partsWarehouse")
	public R submit(@Valid @RequestBody PartsWarehouse partsWarehouse) {
		return R.status(partsWarehouseService.saveOrUpdate(partsWarehouse));
	}

	/**
	 * 新增 配件仓库表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 10)
	@ApiOperation(value = "新增", notes = "传入partsWarehouse")
	public R save(@Valid @RequestBody PartsWarehouse partsWarehouse) {
		return R.status(partsWarehouseService.save(partsWarehouse));
	}

	/**
	 * 删除 配件仓库表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 20)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(partsWarehouseService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * 根据条件自定义分页
	 * @param partsWarehousePageDTO 分页参数
	 * @return 分页结果
	 */
	@PostMapping("/selectPageByCondition")
	@ApiOperationSupport(order = 30)
	@ApiOperation(value = "根据条件自定义分页", notes = "传入partsWarehousePageDTO")
	public R<IPage<PartsWarehousePageVO>> selectPageByCondition(@RequestBody PartsWarehousePageDTO partsWarehousePageDTO) {
		Query query = new Query();
		query.setCurrent(partsWarehousePageDTO.getCurrent());
		query.setSize(partsWarehousePageDTO.getSize());
		IPage<PartsWarehousePageVO> pages
			= partsWarehouseService.selectPageByCondition(Condition.getPage(query),partsWarehousePageDTO);
		return R.data(pages);
	}

	/**
	 * 修改 配件仓库表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 40)
	@ApiOperation(value = "修改", notes = "传入partsWarehouse")
	public R update(@Valid @RequestBody PartsWarehouse partsWarehouse) {
		return R.status(partsWarehouseService.updateById(partsWarehouse));
	}

}
